package org.jactao.common;

import org.jactao.registry.LRegistry;

/**
 * Created by fanzetao on 2018/4/10.
 */
public class LClientConfig {

    private String protocolName;

    private String serializer;

    private LRegistry registry;

    private int timeout;

    public String getProtocolName() {
        return protocolName;
    }

    public void setProtocolName(String protocolName) {
        this.protocolName = protocolName;
    }

    public String getSerializer() {
        return serializer;
    }

    public void setSerializer(String serializer) {
        this.serializer = serializer;
    }

    public LRegistry getRegistry() {
        return registry;
    }

    public void setRegistry(LRegistry registry) {
        this.registry = registry;
    }

    public int getTimeout() {
        return timeout;
    }

    public void setTimeout(int timeout) {
        this.timeout = timeout;
    }

    public void checkRequiredAndDefaulted() {
        if(registry == null)
            throw new LException("registry required");
        else
        if(!registry.running())
            throw new LException("registry not running");

        protocolName = protocolName == null || protocolName == "" ? LConstants.defaultProtocol : protocolName;

        serializer = serializer == null || serializer == "" ? LConstants.defaultSerializer : serializer;
    }
}
